package controller;

import java.util.ArrayList;

import checking.IdGenerator;
import connection.ActivityConnection;
import connection.ProjectConnection;
import connection.TaskConnection;

import model.Activity;
import model.Project;
import model.Resource;
import model.Task;

public class ControllerForDB {

	private IdGenerator oId = new IdGenerator();
	private TaskConnection oTaskConn = new TaskConnection();
	private ActivityConnection oActivityConn = new ActivityConnection();
	private ProjectConnection oProjectConnetion = new ProjectConnection();
	
	///project methods
	public ArrayList<Project> getAllProjects(){
		
		ArrayList<Project> oAllProjects = new ArrayList<Project>();
		oAllProjects = oProjectConnetion.getAllProjectsFromDB();
		System.out.println("All projects in the database are ;\n");
		
		for(int i=0; i<oAllProjects.size(); i++){
			System.out.println(oAllProjects.get(i).getNumber()+" - "+oAllProjects.get(i).getName()+"\n");
		}
		
		return  oAllProjects;
		
	}
	
	public ArrayList<Project> getAllProjectsForPM(int pmId){
		
		ArrayList<Project> projectList = new ArrayList<Project>();
		projectList = oProjectConnetion.getAllProjectsOfPM(pmId);
		
		System.out.println("All projects that you manage are;\n");
		for (int i=0; i<projectList.size(); i++){
			System.out.println(projectList.get(i).getNumber()+" - "+ projectList.get(i).getName()+"\n");
			}
		return projectList;
		}
	
	public Project addProjectToDB(String name,String desc,String proDate,int pManagerId){
		
		Project oProject = new Project(oId.generateId(),name,desc, proDate,pManagerId);
		 oProjectConnetion.addProjectToDB(oProject, pManagerId);
		return oProject; 
		
	}
	
	public void removeProjectFromDB(int projectId){
		
		oProjectConnetion.removeProjectFromDB(projectId);
		System.out.println("Your project is removed.\n");
		
	}
	
	public void updateProjectFromDB(int projectId, String name, String desc, String startDate){
		
		oProjectConnetion.updateProjectFromDB(projectId, name, desc, startDate);
		System.out.println("Your project is updated.\n");
		
	}
	
	public ArrayList<Activity> getAllActivites(int projectId){
		ArrayList<Activity> oActList = new ArrayList<Activity>();
		oActList = oActivityConn.getAllActivityofProject(projectId);
		
		for (int i=0; i<oActList.size(); i++){
			System.out.println(oActList.get(i).getNumber()+" - "+oActList.get(i).getDesc());
		}
		return oActList;
	}
	
	
	
	
	/// activity methods
	public Activity addActivityToDB(String activityDesc,String actDate, String activityDel,int addedProjectId){
		
		Activity oActivity = new Activity(oId.generateId(), activityDesc, actDate, activityDel);
		oActivityConn.addActivityToDB(oActivity,addedProjectId);
		System.out.println("The activity is added. Activity id is; "+oActivity.getNumber());
		return oActivity;
	}
	
	public void removeActivityFromDB(int actId){
		oActivityConn.removeActivityFromDB(actId);
	}
	
	public void updateActivityFromDB(int id,String desc,String startDate,String deliverable){
		oActivityConn.updateActivityFromDB(id, desc, startDate, deliverable);
	}
	
	public ArrayList<Task> getAllTask(int activityId){
		ArrayList<Task > oAllTaskList = new ArrayList<Task>(); 
		oAllTaskList=oTaskConn.getAllTaskofActivity(activityId);
		
		System.out.println("All tasks of your activity is;\n\n");
		for(int i=0; i< oAllTaskList.size(); i++){
			System.out.println(oAllTaskList.get(i).toString()+"\n");
		}
		
		return oAllTaskList;
	}
	
	
	
	
	//task methods
	public Task addTaskToDB(String taskDescription,String taskSDate,int taskEsHours,String taskDeliverable,int addedActivityId){
		
		Task oTask = new Task(oId.generateId(), taskDescription, taskSDate, taskEsHours, taskDeliverable);
		oTaskConn.addTaskToDB(oTask, addedActivityId);
		return oTask;
	}
	
	public void updateTaskFromDB(int id,String desc,String startDate, int estimatedHours, int exactHours, String deliverable){
		oTaskConn.updateTaskFromDB(id, desc, startDate, estimatedHours, exactHours, deliverable);
	}
	
	public void removeTaskFromDB(int taskId){
		oTaskConn.removeTaskFromDB(taskId);
		
	}
	
	
	//resource methods 
	public ArrayList<Resource> getAllResources(int taskId){
		 ArrayList<Resource> resourceList = new  ArrayList<Resource>();
		 
		 for (int i=0; i<resourceList.size(); i++){
			 System.out.println(resourceList.get(i).getResourceId()+" - "+ resourceList.get(i).getName());
		 }
		 return resourceList;
	}
	
	public void getAllPersonFromDB(){
		
	}
	
	public void getAllMaterialsFromDB(){
		
	}
	

	public void getAllPersonOfTaskFromDB(int taskId){
		
	}
	
	public void getAllMaterialsOfTaskFromDB(int taskId){
		
	}
	
	public void assignPersonToTask(int taskId,int personId){
		
	}
	
	public void assignMaterialToTask(int taskId,int materialId){
		
	}
	public void unassingPersonFromTask(int taskId,int personId){
		
	}
	
	public void unassingMaterialFromTask(int taskId,int materialId){
		
	}
	
	
}
